/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package job;

import infr.Logger4j;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

/**
 *
 * @author yjbian
 */
public class CalculateTimeJob implements Job {

    @Override
    public void execute(JobExecutionContext jec) throws JobExecutionException {

        String baseTimeString = "2010-01-01 00:00:00";
        if (jec != null) {
            JobDataMap jobDataMap = jec.getJobDetail().getJobDataMap();
            if (jobDataMap != null && jobDataMap.size() > 0) {
                Object baseTimeObject = jobDataMap.get("BaseTime");
                if (baseTimeObject != null) {
                    baseTimeString = String.valueOf(baseTimeObject);
                }
            }
        }
        long nowTime = Calendar.getInstance().getTimeInMillis();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");

        Date baseDate;
        try {
            baseDate = format.parse(baseTimeString);
            long diff = nowTime - baseDate.getTime();
            Logger4j.info("Base on " + baseTimeString + ",Diff Time:" + diff);
        } catch (ParseException ex) {
            Logger4j.error(ex.getMessage());
        }

    }
}
